﻿using RestApp.BusinessLogic.Code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RestApp.BusinessLogic
{
	public static class LinqExtenssions
	{
		public static IEnumerable<User> FilterUsersForCredentials(this IEnumerable<User> collection, User user)
		{
			if (user.IdRole == (int)UserRolesEnum.User)
			{
				return collection
					.Where(t => !t.IsDelete && t.JobTitle != null && t.JobTitle.CanBePenalted != null
						&& t.JobTitle.CanBePenalted.Value
						&& !t.IsFired)
					.ToList();
			}
			else if (user.IdRole == (int)UserRolesEnum.Manager)
			{
				return collection
					.Where(t => !t.IsDelete && t.IdBossJobPost == user.IdJobPost
						&& t.JobTitle.CanBePenalted.Value
						&& !t.IsFired)
					.ToList();
			}
			else if (user.IdRole == (int)UserRolesEnum.Admin)
			{
				return collection
					.Where(t => !t.IsDelete && !t.IsFired)
					.ToList();
			}
			else
			{
				throw new InvalidOperationException("invalid id role type");
			}
		}
	}
}
